package com.atlin.nrpc.core.service;

import io.vertx.core.Vertx;

/**
 * 服务器
 */
public class VertxHttpServer implements HttpServer {


    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();

        io.vertx.core.http.HttpServer server = vertx.createHttpServer();

/*        server.requestHandler(request -> {
            System.out.println("Received request:" + request.method() + " " + request.uri());
            request.response()
                    .putHeader("content-type", "text/plain")
                    .end("Hello form vert.x HTTP server!");
        });*/

        server.requestHandler(new HttpServerHandler());
        server.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("server is now listening on port " + port);
            } else {
                System.out.println("Failed to start server: " + result.cause());
            }
        });
    }
}
